#include "CBase.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "SGD Wrappers/CSGD_Direct3D.h"
#include "CCamera.h"

CBase::CBase(void)
{
	m_uiRefCount = 1;

	SetPosX(0);
	SetPosY(0);

	SetVelX(0);
	SetVelY(0);

	m_fOffestX =0;
	m_fOffestY =0;


	SetImageID(-1);
	m_bIsActive = true;
	facing_right = true;

	m_fScaleX = 1;
	m_fScaleY = 1;

	m_nType = OBJ_BASE;
}

CBase::~CBase(void)
{
	if(GetImageID() != -1)
		CSGD_TextureManager::GetInstance()->UnloadTexture(GetImageID());	
}

void CBase::Update(float fElapsedTime)
{
	SetPosX(GetPosX() + (GetVelX() * fElapsedTime));
	SetPosY(GetPosY() + (GetVelY() * fElapsedTime));
}

void CBase::Render(void)
{
	if(facing_right)
		CSGD_TextureManager::GetInstance()->Draw(GetImageID(), (int)GetPosX()- CCamera::GetInstance()->GetCameraPosX(), (int)GetPosY()- CCamera::GetInstance()->GetCameraPosY());
	else
		CSGD_TextureManager::GetInstance()->Draw(GetImageID(), ((int)GetPosX() + GetWidth()) - CCamera::GetInstance()->GetCameraPosX(), (int)GetPosY()- CCamera::GetInstance()->GetCameraPosY(), -1.0f);


}

RECT CBase::GetCollisionRect(void)
{
	RECT rCollisionRect = {(LONG)(GetPosX()+m_fOffestX), (LONG)(GetPosY()+m_fOffestY), (LONG)((GetPosX() + GetWidth())+m_fOffestX), 
		(LONG)((GetPosY() + GetHeight())+m_fOffestY )};
	return rCollisionRect;
}

bool CBase::CheckCollision(CBase* pBase)
{
	return (IntersectRect(0, &GetCollisionRect(), &pBase->GetCollisionRect()) == TRUE? true : false);
}

